import re


def main():
    string = '''
        abcd
        abcd
    '''
    pattern = re.compile(r'a(.*)d', re.RegexFlag.S)

    # 2. 提取数据
    result = pattern.findall(string)
    print(result)

    pattern = re.compile('\d+')
    string = "123abc456"
    results = pattern.finditer(string)
    for result in results:
        print(result)

    print(results)

    string = "a;dj jkl,jj; j;sd"
    # split 分组
    pattern = re.compile(r'[; ,]+')
    result = pattern.split(string)
    print(result)

    # sub 交换
    string = "hello world;sjd;ssdjkls;sdjk;crise lyj"
    # 带 空格的词组替换成 #
    pattern = re.compile(r'(\w+) (\w+)')

    # 把 空格的词组 进行交换
    result = pattern.sub(r"\2 \1", string)

    print(result)

    string = '<input type="submit" id="su" value="百度一下" class="bg s_btn">'

    pattern = re.compile(r'<input type="submit" id="(.*?)" value="(.*?)" class="bg s_btn">')

    result = pattern.findall(string)
    print(result)


if __name__ == '__main__':
    main()
